//
//  BaseViewController.m
//  DailyRecord
//
//  Created by Gin on 2022/3/24.
//

#import "BaseViewController.h"

@interface BaseViewController ()

@property (nonatomic, strong, readwrite) BaseNavigationBar *navigationBar;

@end

@implementation BaseViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = UIColor.whiteColor;
    [self.view addSubview:self.navigationBar];
    [self.navigationBar mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.top.mas_equalTo(0);
        make.height.mas_equalTo(kNavigationBarHeight);
    }];
    [self initUI];
    [self setUpContraints];
}

- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    self.navigationController.navigationBar.hidden = YES;
    if (self.navigationController.viewControllers.count > 1) {
        self.navigationBar.backBtn.hidden = NO;
    }
}

- (void)initUI{}

- (void)setUpContraints{}

- (void)setCustomNavigationTitle:(NSString *)title{
    [self.navigationBar setTitle:title];
}

- (void)toBack{
    [self.navigationController popViewControllerAnimated:YES];
}

#pragma mark -- setter&&getter

- (BaseNavigationBar *)navigationBar{
    if (!_navigationBar) {
        _navigationBar = [BaseNavigationBar new];
        [_navigationBar.backBtn addTarget:self action:@selector(toBack) forControlEvents:UIControlEventTouchUpInside];
    }
    return _navigationBar;
}

@end
